<template>
  <div class="container">
    <h1>例子</h1>
    <button @click="addItem">新增</button>

    <div class="list-container">
      <transition-group name="slide-fade" tag="ul">
        <li v-for="(item, index) in items" :key="item">
          {{ item }}
          <button @click="removeItem(index)">删除</button>
        </li>
      </transition-group>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TransitionDemo',
  data() {
    return {
      items: [],
    }
  },
  methods: {
    addItem() {
      this.items.push(`项 ${this.items.length + 1}`)
    },
    removeItem(index) {
      this.items.splice(index, 1)
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  width: 200px;
}

.list-container {
  margin: 20px 0;

  ul {
    list-style-type: none;
    padding: 0;

    li {
      display: flex;
      justify-content: space-between;
      padding: 10px;
      border: 1px solid #ccc;
      margin-bottom: 5px;
      border-radius: 5px;
      transition: all 0.3s ease;
    }
  }
}

.slide-fade-enter-active,
.slide-fade-leave-active {
  transition: all 0.3s ease;
}

.slide-fade-enter {
  opacity: 0;
  transform: translateX(100px);
}

.slide-fade-enter-to {
  opacity: 1;
  transform: translateX(0);
}

.slide-fade-leave {
  opacity: 1;
  transform: translateX(0);
}

.slide-fade-leave-to {
  opacity: 0;
  transform: translateX(100px);
}
</style>
